<!-- 家庭医生签约 -->
<template>
	<view class="signed-wrapper">
		<p class="title">{{info.title}}</p>
		<p class="money">费用：￥ {{info.moneys}}</p>
		<div style="margin-bottom: 10px;"></div>
		<uni-section title="擅长方向" type="line">
			<view class="tag-view" v-for="item in info.label">
				<u-tag :text="item" type="success" plain=""></u-tag>
			</view>
		</uni-section>
		<uni-section title="服务包" type="line">
			<view class="service-item">

			</view>
		</uni-section>
		<uni-section title="就诊人" type="line">
			<view style="box-sizing: border-box;">
				<view class="user-item" :class="{'active': currentUser.j_id == item.j_id}"
					v-for="(item, index) in userCardList" :key="index" @click="selectCurrentUser(item)">
					<p>{{item.names}}</p>
				</view>
			</view>
		</uni-section>

		<view class="fixedfoot">
			<view class="clickbtn" @click="doSubmit()">点击签约{{info.title}}</view>
		</view>
	</view>
</template>

<script>
	import {getCurrentDay} from '../../common/dateUtil.js'
	export default {
		data() {
			return {
				info: {},

				userCardList: [],
				currentUser: {}
			}
		},
		onLoad(option) {
			this.api_detail(option.id)

			this.api_cardlist()
		},
		methods: {
			selectCurrentUser(item) {
				this.currentUser = item
			},

			doSubmit() {
				if (!this.currentUser.j_id) {
					uni.showToast({
						title: '请选择就诊人',
						icon: "none"
					});
				} else {
					let openid = uni.getStorageSync('openid')
					this.$app._get('team.orders', {
						tid: this.info.id,
						money: this.info.money,
						openid: openid,
						start: getCurrentDay(),
						end: getCurrentDay(),
						coupon_id: '',
						j_id: this.currentUser.j_id,
						y_money: this.info.money,
						key_words: '',
						addnum: 0
					}, (res) => {
						console.log(res)
						uni.navigateTo({
							url: '/pages/global/successMessage?msg=签约成功'
						})
					})
				}
			},

			api_detail(id) {
				let openid = uni.getStorageSync('openid')
				this.$app._get('team.detail', {
					id: id,
					openid: openid
				}, (res) => {
					this.info = res
					console.log(res)
				})
			},

			api_cardlist() {
				let openid = uni.getStorageSync('openid')
				this.$app._post_form("entry/wxapp/apipatient.cardlist", {
					'openid': openid
				}, (res) => {
					if (res.status === 1) {
						this.userCardList = res.data
					}
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.signed-wrapper {
		width: 100%;
		height: 100%;
		background-color: #fff;
		box-sizing: border-box;
		padding: 15px;
		position: relative;

		.title {
			font-size: 1.1rem;
		}

		.money {
			font-size: .8rem;
			color: #ff9800;
		}

		.tag-view {
			display: inline-block;
			margin-right: 5px;
			margin-bottom: 5px;
		}

		.user-item {
			width: auto;
			font-size: 0.8rem;
			color: #757575;
			background-color: #eee;
			border-radius: 6px;
			padding: 10px;
			margin-bottom: 5px;

			&.active {
				background-color: #41C177;
				color: #fff;
			}
		}

		.fixedfoot {
			width: 100%;
			position: fixed;
			bottom: 0px;
			left: 0;
			display: flex;
			align-items: center;
			justify-content: space-between;
			background: white;

			.clickbtn {
				width: 100%;
				height: 50px;
				line-height: 50px;
				font-size: 1.2rem;
				color: #fff;
				text-align: center;
				background: #41C177;
			}
		}
	}
</style>